home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / UPC12BS1.ZIP / MAIL / MAILBLIB.C < prev    next >
C/C++ Source or Header  |  1993-09-20  |  39KB  |  1,114 lines

  1. /*--------------------------------------------------------------------*/
  2. /*       m a i l b l i b . c                                          */
  3. /*                                                                    */
  4. /*       Support routines for UUPC/extended mail user agent           */
  5. /*--------------------------------------------------------------------*/
  6.  
  7. /*--------------------------------------------------------------------*/
  8. /*       Changes Copyright (c) 1989-1993 by Kendra Electronic         */
  9. /*       Wonderworks.                                                 */
  10. /*                                                                    */
  11. /*       All rights reserved except those explicitly granted by       */
  12. /*       the UUPC/extended license agreement.                         */
  13. /*--------------------------------------------------------------------*/
  14.  
  15. /*--------------------------------------------------------------------*/
  16. /*                          RCS Information                           */
  17. /*--------------------------------------------------------------------*/
  18.  
  19. /*
  20.  *    $Id: mailblib.c 1.4 1993/09/20 04:41:54 ahd Exp $
  21.  *
  22.  *    Revision history:
  23.  *    $Log: mailblib.c $
  24.  * Revision 1.4  1993/09/20  04:41:54  ahd
  25.  * OS/2 2.x support
  26.  *
  27.  * Revision 1.3  1993/07/31  16:26:01  ahd
  28.  * Changes in support of Robert Denny's Windows support
  29.  *
  30.  */
  31.  
  32. /*--------------------------------------------------------------------*/
  33. /*                        System include files                        */
  34. /*--------------------------------------------------------------------*/
  35.  
  36. #include <stdio.h>
  37. #include <string.h>
  38. #include <stdlib.h>
  39. #include <ctype.h>
  40.  
  41. #if defined(_Windows)
  42. #include <windows.h>
  43. #endif
  44.  
  45. /*--------------------------------------------------------------------*/
  46. /*                    UUPC/extended include files                     */
  47. /*--------------------------------------------------------------------*/
  48.  
  49. #include "lib.h"
  50. #include "address.h"
  51. #include "mail.h"
  52. #include "maillib.h"
  53. #include "mailblib.h"
  54. #include "mailsend.h"
  55. #include "hlib.h"
  56. #include "alias.h"
  57. #include "expath.h"
  58.  
  59. /*--------------------------------------------------------------------*/
  60. /*                      Variables global to file                      */
  61. /*--------------------------------------------------------------------*/
  62.  
  63. static int *item_list = NULL;
  64. static size_t next_item;
  65.  
  66. currentfile();
  67.  
  68. /*--------------------------------------------------------------------*/
  69. /*                    Internal function prototypes                    */
  70. /*--------------------------------------------------------------------*/
  71.  
  72. static boolean SearchUser( char *token , char **input, const int bits);
  73.  
  74. static boolean SearchSubject( char *token,
  75.                               char **input,
  76.                               char *trailing,
  77.                               const int bits);
  78.  
  79. /*--------------------------------------------------------------------*/
  80. /*                     Externally known functions                     */
  81. /*--------------------------------------------------------------------*/
  82.  
  83. /*--------------------------------------------------------------------*/
  84. /*    S h o w A l i a s                                               */
  85. /*                                                                    */
  86. /*    Print the expansion of an alias                                 */
  87. /*--------------------------------------------------------------------*/
  88.  
  89. void ShowAlias( const char *alias)
  90. {
  91.    char *fullname = AliasByNick( alias );
  92.    static int level = 0;
  93.    int column = level * 2;
  94.  
  95.    if ( alias == NULL )
  96.    {
  97.       printf("Missing operand\n");
  98.       return;
  99.    }
  100.  
  101. /*--------------------------------------------------------------------*/
  102. /*                        Indent nested calls                         */
  103. /*--------------------------------------------------------------------*/
  104.  
  105.    while(column-- > 0 )
  106.       putchar(' ');
  107.  
  108. /*--------------------------------------------------------------------*/
  109. /*       Show the alias, breaking it down recursively if need be      */
  110. /*--------------------------------------------------------------------*/
  111.  
  112.    if (fullname == NULL)
  113.    {
  114.       char user[MAXADDR];
  115.       char path[MAXADDR];
  116.       char node[MAXADDR];
  117.  
  118.       printf("No alias defined for \"%s\"\n",alias);
  119.  
  120.       column = level * 2 + 2;
  121.       while(column-- > 0 )
  122.          putchar(' ');
  123.  
  124.       user_at_node(alias, path, node, user);
  125.                               /* Reduce address to basics */
  126.       printf("(%s@%s via %s)\n", user, node, path);
  127.    }
  128.    else {
  129.  
  130.       printf("%s is aliased to %s\n", alias, fullname);
  131.  
  132.       if (*fullname == '"')
  133.       {
  134.  
  135.          if ( debuglevel > 1)
  136.          {
  137.             char user[MAXADDR];
  138.             char path[MAXADDR];
  139.             char node[MAXADDR];
  140.  
  141.             ExtractAddress(user,fullname, FALSE);
  142.             user_at_node(user,path,node,user);
  143.                                     /* Reduce address to basics */
  144.             column = level * 2 + 2;
  145.             while(column-- > 0 )
  146.                putchar(' ');
  147.  
  148.             printf("(%s@%s via %s)\n", user, node, path);
  149.          }
  150.       }
  151.       else {
  152.          char buf[LSIZE];
  153.  
  154.          strcpy( buf, fullname );
  155.          fullname = strtok( buf , WHITESPACE "," );
  156.  
  157.          while (fullname != NULL )
  158.          {
  159.             char *save = strtok( NULL , "");
  160.             level++;             /* Bump up a level for recursive calls */
  161.             ShowAlias(fullname);
  162.             level--;             /* Restore indent level                */
  163.             fullname = strtok( save , " ," );
  164.          } /* while */
  165.       } /* else */
  166.    } /* else */
  167.  
  168. } /* ShowAlias */
  169.  
  170. /*--------------------------------------------------------------------*/
  171. /*    S a v e I t e m                                                 */
  172. /*                                                                    */
  173. /*    Save an item in another mailbox                                 */
  174. /*--------------------------------------------------------------------*/
  175.  
  176. boolean SaveItem( const int item,
  177.                const boolean delete,
  178.                const copyopt headers,
  179.                char *fname,
  180.                const ACTION verb)
  181. {
  182.    char filename[FILENAME_MAX];
  183.    char *s = "?";
  184.    FILE *stream;
  185.  
  186.    if (fname == NULL)
  187.       fname = "~/mbox";
  188.  
  189. /*--------------------------------------------------------------------*/
  190. /*                        Build the file name                         */
  191. /*--------------------------------------------------------------------*/
  192.  
  193.    switch (*fname)
  194.    {
  195.       case '=':         /* relative to home directory? */
  196.             printf("Syntax is obsolete ... use \"~/%s\"", fname + 1 );
  197.             mkfilename(filename, E_homedir, ++fname);
  198.             break;
  199.  
  200.       case '+':         /* Relative to mail directory?   */
  201.             mkmailbox(filename, ++fname);
  202.             break;
  203.  
  204.       default:
  205.       case '~':         /* Relative to home directory?            */
  206.             strcpy( filename , fname );
  207.             if (expand_path( filename , NULL, E_homedir, E_mailext ) == NULL)
  208.                return FALSE;
  209.             break;
  210.    }  /* end switch */
  211.  
  212. /*--------------------------------------------------------------------*/
  213. /*               Announce our action based on the verb                */
  214. /*--------------------------------------------------------------------*/
  215.  
  216.    switch( verb )
  217.    {
  218.       case M_COPY:
  219.          s = "Copying";
  220.          break;
  221.  
  222.       case M_SAVE:
  223.          s = "Saving";
  224.          break;
  225.  
  226.       case M_WRITE:
  227.          s = "Writing";
  228.          break;
  229.    } /* switch */
  230.  
  231.    printf("%s item %d to %s\n", s , item + 1, filename );
  232.  
  233. /*--------------------------------------------------------------------*/
  234. /*                     Open the mailox to save to                     */
  235. /*--------------------------------------------------------------------*/
  236.  
  237.    if ((stream = FOPEN(filename, "a",TEX